<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PortalUser.php 368 2010-02-06 20:23:50Z steen.rabol@gmail.com $
 * @package Pradoportal.Common
 *
 */

Prado::using('System.Security.TUser');

/**
 *
 * @package Pradoportal.Common
 */
class PortalUser extends TComponent implements IUser
{
	private	$_fullname	= null;
	private $_manager	= null;
	private $_name		= null;
	private $_roleid	= null;
	private $_rolename	= null;
	private $_id		= null;
	private $_isguest	= true;
	private $_email		= null;
	private $_status	= null;
	private $_sitenews	= null;
	private $_regtime	= null;
	private $_culture	= null;

	public function __construct($Manager=NULL)
	{
		$this->_manager = $Manager;
	}

	public function getManager()
	{
		return $this->_manager;
	}

	// Following 2 functions makes most work in this class. They are
	// responsible of saving and restoring user instance to/from session.

	public function saveToString()
	{
		return serialize(
						 array($this->Id,
							   $this->Name,
							   $this->FullName,
							   $this->RoleId,
							   $this->RoleName,
							   $this->Email,
							   $this->RegTime,
							   $this->Status,
							   $this->SiteNews,
							   $this->IsGuest,
							   $this->Culture));
	}

	public function loadFromString($data)
	{
		if (!empty($data))
		{
			$array = unserialize($data);
			$this->Id		= $array[0];
			$this->Name		= $array[1];
			$this->FullName	= $array[2];
			$this->RoleId	= $array[3];
			$this->RoleName	= $array[4];
			$this->Email	= $array[5];
			$this->RegTime	= $array[6];
			$this->Status	= $array[7];
			$this->SiteNews	= $array[8];
			$this->IsGuest	= $array[9];
			$this->Culture	= $array[10];
		}
		return $this;
	}

	// Fake methods! We don't really need these but IUser insists on 'em.
	public function getRoles() {}
	public function setRoles($value) {}
	
	public function isInRole($value)
	{
		return false;
	}

	public function getCulture()
	{
		return $this->_culture;
	}
	
	public function setCulture($value)
	{
		$this->_culture = TPropertyValue::ensureString($value);
	}
	
	public function getName()
	{
		return $this->_name;
	}

	public function setName($value)
	{
		$this->_name = TPropertyValue::ensureString($value);
	}

	public function getFullName()
	{
		return $this->_fullname;
	}

	public function setFullName($value)
	{
		$this->_fullname = TPropertyValue::ensureString($value);
	}

	public function getRoleId()
	{
		return $this->_roleid;
	}

	public function setRoleId($value)
	{
		$this->_roleid = TPropertyValue::ensureInteger($value);
	}

	public function getRoleName()
	{
		return $this->_rolename;
	}

	public function setRoleName($value)
	{
		$this->_rolename = TPropertyValue::ensureString($value);
	}

	public function getId()
	{
		return $this->_id;
	}

	public function setId($value)
	{
		$this->_id = TPropertyValue::ensureInteger($value);
	}

	public function getIsGuest()
	{
		return $this->_isguest;
	}

	public function getIsAdmin()
	{
		return ($this->RoleId == TPropertyValue::ensureInteger($this->Manager->Application->Parameters['AdminRole']));
	}

	public function setIsGuest($value)
	{
		$this->_isguest = TPropertyValue::ensureBoolean($value);
	}

	public function getEmail()
	{
		return $this->_email;
	}

	public function setEmail($value)
	{
		$this->_email	= TPropertyValue::ensureString($value);
	}

	public function getStatus()
	{
		return $this->_status;
	}

	public function setStatus($value)
	{
		$this->_status = TPropertyValue::ensureInteger($value);
	}

	public function getSiteNews()
	{
		return $this->_sitenews;
	}

	public function setSiteNews($value)
	{
		$this->_sitenews = TPropertyValue::ensureInteger($value);
	}

	public function getRegTime()
	{
		return $this->_regtime;
	}

	public function setRegTime($value)
	{
		$this->_regtime = TPropertyValue::ensureInteger($value);
	}
}
?>